package org.richin.servlet.Response.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.servlet.ServletOutputStream;

/**
 * A memory-backed {@link ServletOutputStream}.
 *
 * @author Middleware
 * @version $Revision$
 *
 */
public class ByteArrayServletOutputStream extends ServletOutputStream
{
  /** Memory-backed stream backing this instance */
  private ByteArrayOutputStream baos;
  
  
  /**
   * Creates a new instance with the default backing stream.
   */
  public ByteArrayServletOutputStream()
  {
    this(new ByteArrayOutputStream());
  }


  /**
   * Creates a new instance with the given backing stream.
   * @param os Backing stream.
   */
  public ByteArrayServletOutputStream(final ByteArrayOutputStream os)
  {
    this.baos = os;
  }


  /** {@inheritDoc} */
  @Override
  public void write(int b) throws IOException
  {
    baos.write(b);
  }
}
